<?php
class Facebook_model extends CI_Model {
	
	public function __construct()
	{
		parent::__construct();
                
		$fb=$this->config->load('facebook', TRUE);

                $config = array(
                        'appId'  => $fb['test_aum']['appId'],
                        'secret' => $fb['test_aum']['secret'],
                        'fileUpload' => true, // Indicates if the CURL based @ syntax for file uploads is enabled.
                        );
		
		$this->load->library('Facebook', $config);
		
		$user = $this->facebook->getUser();

		// We may or may not have this data based on whether the user is logged in.
		//
		// If we have a $user id here, it means we know the user is logged into
		// Facebook, but we don't know if the access token is valid. An access
		// token is invalid if the user logged out of Facebook.
		$profile = null;
		if($user)
		{
			try {
			    // Proceed knowing you have a logged in user who's authenticated.
				$profile = $this->facebook->api('/me?fields=id,name,link,email');
			} catch (FacebookApiException $e) {
				error_log($e);
			    $user = null;
			}		
		}
		//$par['scope'] = "friends_about_me,user_about_me,user_relationships,read_stream,user_birthday";
                $par['scope'] = "user_about_me, friends_about_me, user_activities, friends_activities, user_birthday, friends_birthday, user_checkins, friends_checkins, user_education_history, friends_education_history, user_hometown, friends_hometown, user_interests, friends_interests, user_likes, friends_likes, user_status, friends_status, user_videos, friends_videos, user_website, friends_website, user_work_history, friends_work_history, read_friendlists, read_stream, publish_checkins, publish_stream";
		$fb_data = array(
						'me' => $profile,
						'uid' => $user,
						'loginUrl' => $this->facebook->getLoginUrl($par),
						'logoutUrl' => $this->facebook->getLogoutUrl(),
					);

		$this->session->set_userdata('fb_data', $fb_data);
	}
        
        public function get_friend()
        {
            $result = $this->facebook->api('/me/friends');  
            return $result;
        }
        
        public function get_status()
        {
            $result = $this->facebook->api('/me/statuses');  
            return $result;
        }
        
        public function get_user_info()
        {
            //$result = $this->facebook->api('/me?fields=id,name,link,email,first_name,last_name,gender,work');  
            $result = $this->facebook->api('/me');
            return $result;
        }
        
}
